/*
 * version date author 
 * ────────────────────────────────── 
 * 1.0  Nov 27, 2012 Neal Miao 
 * 
 * Copyright(c) 2012, by HTWater. All Rights Reserved.
 */
package cn.miao.demo.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.miao.demo.service.TestService;
import cn.miao.framework.action.DoAction;
import cn.miao.framework.endec.RSA;
import cn.miao.framework.entity.Responser;
import cn.miao.framework.factory.ServiceFactory;
import cn.miao.framework.util.Cache;
import cn.miao.framework.util.FileUtil;

/**
 * 
 * 
 * @author Neal Miao
 * @version
 * @since v 1.0
 * @Date Nov 27, 2012 4:46:37 PM
 * 
 * @see
 */
public class TestAction extends DoAction {

	/**
	 * 获取公钥
	 * 
	 * @return Responser
	 * @since v 1.0
	 */
	public Responser getPublicKey() {
		responser.setRtType(JSON);
		responser.setRtString(parseJSON(RSA.getPublicKeyMap()));
		return responser;
	}

	public Responser testService() {
		TestService service = (TestService) ServiceFactory.getService("test");
		responser.setRtType(JSON);
		responser.setRtString(parseJSON(service.getSomething()));
		return responser;
	}

	public Responser testJson() {
		System.out.println(session);
		responser.setRtType(JSON);
		Map<String, Object> map = new HashMap<String, Object>();
		map.putAll(params.getParams());
		map.put("date", new Date());
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map2 = new HashMap<String, Object>();
		map2.put("dddd", new Date());
		map2.put("cc", "dd");
		list.add(map2);
		map.put("aaa", list);
		responser.setRtString(parseJSON(map));
		return responser;
	}

	public Responser testText() {
		responser.setRtType(TEXT);
		responser.setRtString(session.getServletContext().getRealPath("/"));
		return responser;
	}

	public Responser testNone() {
		responser.setRtType(NONE);
		return responser;
	}

	public Responser testRedirect(Map<String, Object> params) {
		responser.setRtType(REDIRECT);
		responser.setRtString("home.html");
		return responser;
	}

	public Responser getFileList() {
		responser.setRtType(JSON);
		responser.setRtString(parseJSON(FileUtil.getFileList(Cache.downloadRoot
				+ "/" + params.getParam("path"))));
		return responser;
	}
}
